

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon.png">
  <link rel="icon" href="/img/favicon.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="John Doe">
  <meta name="keywords" content="">
  
    <meta name="description" content="什么是 sedsed 是一种流编辑器，它是文本处理中非常中的工具，能够完美的配合正则表达式使用，功能不同凡响。处理时，把当前处理的行存储在临时缓冲区中，称为“模式空间”（pattern space），接着用sed命令处理缓冲区中的内容，处理完成后，把缓冲区的内容送往屏幕。接着处理下一行，这样不断重复，直到文件末尾。文件内容并没有 改变，除非你使用重定向存储输出。Sed主要用来自动编辑一个或多个文件">
<meta property="og:type" content="article">
<meta property="og:title" content="shell-流编辑sed">
<meta property="og:url" content="http://example.com/2019/05/28/shell/shell-%E6%B5%81%E7%BC%96%E8%BE%91sed/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="什么是 sedsed 是一种流编辑器，它是文本处理中非常中的工具，能够完美的配合正则表达式使用，功能不同凡响。处理时，把当前处理的行存储在临时缓冲区中，称为“模式空间”（pattern space），接着用sed命令处理缓冲区中的内容，处理完成后，把缓冲区的内容送往屏幕。接着处理下一行，这样不断重复，直到文件末尾。文件内容并没有 改变，除非你使用重定向存储输出。Sed主要用来自动编辑一个或多个文件">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2019-05-28T05:33:35.000Z">
<meta property="article:modified_time" content="2022-02-10T03:11:05.875Z">
<meta property="article:author" content="John Doe">
<meta property="article:tag" content="Linux">
<meta property="article:tag" content="Shell">
<meta name="twitter:card" content="summary_large_image">
  
  
  <title>shell-流编辑sed - Hexo</title>

  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@4/github-markdown.min.css" />
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/hint.css@2/hint.min.css" />

  
    
    
      
      <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@10/styles/github-gist.min.css" />
    
  

  
    <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.css" />
  


<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.8.13","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"right","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"copy_btn":true,"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 6.0.0"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>LZDF</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner" id="banner" parallax=true
         style="background: url('/img/default.png') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="page-header text-center fade-in-up">
            <span class="h2" id="subtitle" title="shell-流编辑sed">
              
            </span>

            
              <div class="mt-3">
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2019-05-28 13:33" pubdate>
        2019年5月28日 下午
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      10k 字
    </span>
  

  
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      87 分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">shell-流编辑sed</h1>
            
            <div class="markdown-body">
              <h1 id="什么是-sed"><a href="#什么是-sed" class="headerlink" title="什么是 sed"></a>什么是 sed</h1><p><strong>sed</strong> 是一种流编辑器，它是文本处理中非常中的工具，能够完美的配合正则表达式使用，功能不同凡响。处理时，把当前处理的行存储在临时缓冲区中，称为“模式空间”（pattern space），接着用sed命令处理缓冲区中的内容，处理完成后，把缓冲区的内容送往屏幕。接着处理下一行，这样不断重复，直到文件末尾。文件内容并没有 改变，除非你使用重定向存储输出。Sed主要用来自动编辑一个或多个文件；简化对文件的反复操作；编写转换程序等。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><code class="hljs bash">说明：功能强大的流式文本编辑器<br>用法: sed [选项]... &#123;脚本(如果没有其他脚本)&#125; [输入文件]...<br><br>  -n, --quiet, --silent<br>                 取消自动打印模式空间<br>  -e 脚本, --expression=脚本<br>                 添加“脚本”到程序的运行列表<br>  -f 脚本文件, --file=脚本文件<br>                 添加“脚本文件”到程序的运行列表<br>  --follow-symlinks<br>                 直接修改文件时跟随软链接<br>  -i[SUFFIX], --in-place[=SUFFIX]<br>                 edit files <span class="hljs-keyword">in</span> place (makes backup <span class="hljs-keyword">if</span> SUFFIX supplied)<br>  -l N, --line-length=N<br>                 指定“l”命令的换行期望长度<br>  --posix<br>                 关闭所有 GNU 扩展<br>  -E, -r, --regexp-extended<br>                 use extended regular expressions <span class="hljs-keyword">in</span> the script<br>                 (<span class="hljs-keyword">for</span> portability use POSIX -E).<br>  -s, --separate<br>                 consider files as separate rather than as a single,<br>                 continuous long stream.<br>      --sandbox<br>                 operate <span class="hljs-keyword">in</span> sandbox mode.<br>  -u, --unbuffered<br>                 从输入文件读取最少的数据，更频繁的刷新输出<br>  -z, --null-data<br>                 separate lines by NUL characters<br>      --<span class="hljs-built_in">help</span>     打印帮助并退出<br>      --version  输出版本信息并退出<br><br>如果没有 -e, --expression, -f 或 --file 选项，那么第一个非选项参数被视为<br>sed脚本。其他非选项参数被视为输入文件，如果没有输入文件，那么程序将从标准<br>输入读取数据。<br>GNU sed home page: &lt;http://www.gnu.org/software/sed/&gt;.<br>General <span class="hljs-built_in">help</span> using GNU software: &lt;http://www.gnu.org/gethelp/&gt;.<br>E-mail bug reports to: &lt;bug-sed@gnu.org&gt;.<br><br></code></pre></td></tr></table></figure>



<h1 id="sed示例"><a href="#sed示例" class="headerlink" title="sed示例"></a>sed示例</h1><h2 id="sed工作方式"><a href="#sed工作方式" class="headerlink" title="sed工作方式"></a>sed工作方式</h2><p><code>sed</code> 通过对输入数据执行任意数量用户指定的编辑操作（命令）。<code>sed</code> 是基于行的，因此按顺序对每一行执行命令。然后将其结果写入标准输出。</p>
<p><strong>示例</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs bash">$ head -n10 /etc/passwd &gt; /tmp/passwd.bak <span class="hljs-comment"># 将 /etc/passwd 文件的头10行复制到 /tmp/passwd.bak 文件中</span><br>$ cat /tmp/passwd.bak <span class="hljs-comment"># 查看 /tmp/passwd.bak 文件内容</span><br>root:x:0:0:root:/root:/bin/bash<br>daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin<br>bin:x:2:2:bin:/bin:/usr/sbin/nologin<br>sys:x:3:3:sys:/dev:/usr/sbin/nologin<br>sync:x:4:65534:sync:/bin:/bin/sync<br>games:x:5:60:games:/usr/games:/usr/sbin/nologin<br>man:x:6:12:man:/var/cache/man:/usr/sbin/nologin<br>lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin<br>mail:x:8:8:mail:/var/mail:/usr/sbin/nologin<br>news:x:9:9:news:/var/spool/news:/usr/sbin/nologin<br>$ sed -e <span class="hljs-string">&#x27;d&#x27;</span> /tmp/passwd.bak <span class="hljs-comment"># 删除缓冲区中每一行，输出为空</span><br>$ sed -e <span class="hljs-string">&#x27;5d&#x27;</span> /tmp/passwd.bak <span class="hljs-comment"># 删除缓冲区中第5行，输出结果</span><br></code></pre></td></tr></table></figure>

<p><strong>注意</strong></p>
<p>在上述示例中：</p>
<p>1）根本没有修改 <code>/tmp/passwd.bak</code> 文件</p>
<p>2）<code>sed</code> 是面向行的，即 <code>sed</code> 对给定的缓冲区数据是一行一行进行处理的</p>
<p>3）养成使用单引号括起 <code>sed</code> 命令的习惯，这样可以禁用 shell 扩展</p>
<h2 id="sed工作的地址范围"><a href="#sed工作的地址范围" class="headerlink" title="sed工作的地址范围"></a>sed工作的地址范围</h2><p><strong>工作范围</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs bash">$ sed -e <span class="hljs-string">&#x27;1,5d&#x27;</span> /tmp/passwd.bak<br>games:x:5:60:games:/usr/games:/usr/sbin/nologin<br>man:x:6:12:man:/var/cache/man:/usr/sbin/nologin<br>lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin<br>mail:x:8:8:mail:/var/mail:/usr/sbin/nologin<br>news:x:9:9:news:/var/spool/news:/usr/sbin/nologin<br></code></pre></td></tr></table></figure>

<p><code>/tmp/passwd.bak</code> 一共10行数据，这里通过给 <code>sed</code> 传递  <code> &#39;1,5d&#39;</code> ，其中 <code>d</code> 是删除命令，作用与 1到5行。因此这条命令作用就是删除这个文件缓冲区的第一到第五行。</p>
<p><strong>忽略注释</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><code class="hljs bash">$ cat /etc/rc.local <span class="hljs-comment"># 注释1</span><br><span class="hljs-comment">#!/bin/sh -e</span><br><span class="hljs-comment">#</span><br><span class="hljs-comment"># rc.local</span><br><span class="hljs-comment">#</span><br><span class="hljs-comment"># This script is executed at the end of each multiuser runlevel.</span><br><span class="hljs-comment"># Make sure that the script will &quot;exit 0&quot; on success or any other</span><br><span class="hljs-comment"># value on error.</span><br><span class="hljs-comment">#</span><br><span class="hljs-comment"># In order to enable or disable this script just change the execution</span><br><span class="hljs-comment"># bits.</span><br><span class="hljs-comment">#</span><br><span class="hljs-comment"># By default this script does nothing.</span><br><br>service php-fpm start<br>service mysql start<br>service nginx start<br><br><span class="hljs-built_in">exit</span> 0<br>$ sed -e <span class="hljs-string">&#x27;/^#/d&#x27;</span> /etc/rc.local <span class="hljs-comment"># 注释2</span><br><br>service php-fpm start<br>service mysql start<br>/usr/<span class="hljs-built_in">local</span>/nginx/sbin/nginx<br><br><span class="hljs-built_in">exit</span> 0<br></code></pre></td></tr></table></figure>

<p>注释1：查看 <code>/etc/rc.local</code> 文件克制，文件中包含注释（以 <code>#</code> 开头的行）、空格和寻常命令；注释2：成功删除所有注释信息。</p>
<p>删除注册的关键在于规则表达式 <code>&#39;/^#/&#39;</code>，<code>&#39;/^#/&#39;</code> 表示以’#‘开头的行，通过 ’d‘ 命令删除该行。</p>
<p>​                                          <strong>sed 中使用的规则表达式字符</strong></p>
<table>
<thead>
<tr>
<th align="center">字符</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td align="center">^</td>
<td>行首匹配</td>
</tr>
<tr>
<td align="center">$</td>
<td>行尾匹配</td>
</tr>
<tr>
<td align="center">.</td>
<td>任一字符匹配</td>
</tr>
<tr>
<td align="center">*</td>
<td>与前一个字符的零个或多个匹配</td>
</tr>
<tr>
<td align="center">[]</td>
<td>与 [] 之内的所有字符匹配</td>
</tr>
</tbody></table>
<p>​                                      <strong>sed 中的规则表达式实例</strong></p>
<table>
<thead>
<tr>
<th align="center">规则表达式</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td align="center">/./</td>
<td>将与包含至少一个字符的任何行匹配</td>
</tr>
<tr>
<td align="center">/../</td>
<td>将与包含至少两个字符的任何行匹配</td>
</tr>
<tr>
<td align="center">/^#/</td>
<td>将与以 ’#‘ 开头的任意行匹配，通常这是注释</td>
</tr>
<tr>
<td align="center">/^$/</td>
<td>将与所有空行匹配</td>
</tr>
<tr>
<td align="center">/}^/</td>
<td>将与 ’}‘ 结束的任意行匹配</td>
</tr>
<tr>
<td align="center">/} *^/</td>
<td>注意在 ’}‘ 后面有一个空格，这将与 ’}‘ 后面跟随零个或多个空格结束的任意行匹配</td>
</tr>
<tr>
<td align="center">/[abc]/</td>
<td>将与包含小写字母 ’a‘ 或 ’b‘ 或 ’c‘ 的任意行匹配</td>
</tr>
<tr>
<td align="center">/^[abc]/</td>
<td>将与以 ’a‘ 或 ’b‘ 或 ’c‘ 开始的任意行匹配</td>
</tr>
</tbody></table>
<p><strong>示例</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><code class="hljs bash">$ sed -e <span class="hljs-string">&#x27;/^#/d&#x27;</span> /etc/rc.local <span class="hljs-comment"># 删除缓冲区所有注释行</span><br><br>service php-fpm start<br>service mysql start<br>/usr/<span class="hljs-built_in">local</span>/nginx/sbin/nginx<br><br><span class="hljs-built_in">exit</span> 0<br>$ sed -n -e <span class="hljs-string">&#x27;/^#/p&#x27;</span> /etc/rc.local <span class="hljs-comment"># 显示缓冲区所有注释行</span><br><span class="hljs-comment">#!/bin/sh -e</span><br><span class="hljs-comment">#</span><br><span class="hljs-comment"># rc.local</span><br><span class="hljs-comment">#</span><br><span class="hljs-comment"># This script is executed at the end of each multiuser runlevel.</span><br><span class="hljs-comment"># Make sure that the script will &quot;exit 0&quot; on success or any other</span><br><span class="hljs-comment"># value on error.</span><br><span class="hljs-comment">#</span><br><span class="hljs-comment"># In order to enable or disable this script just change the execution</span><br><span class="hljs-comment"># bits.</span><br><span class="hljs-comment">#</span><br><span class="hljs-comment"># By default this script does nothing.</span><br><span class="hljs-comment">#/etc/init.d/nginx start</span><br>$ sed -e <span class="hljs-string">&#x27;/^[^#]/d&#x27;</span> /etc/rc.local <span class="hljs-comment"># 删除不是以 # 号开头的行（空行没有被删除）</span><br><span class="hljs-comment">#!/bin/sh -e</span><br><span class="hljs-comment">#</span><br><span class="hljs-comment"># rc.local</span><br><span class="hljs-comment">#</span><br><span class="hljs-comment"># This script is executed at the end of each multiuser runlevel.</span><br><span class="hljs-comment"># Make sure that the script will &quot;exit 0&quot; on success or any other</span><br><span class="hljs-comment"># value on error.</span><br><span class="hljs-comment">#</span><br><span class="hljs-comment"># In order to enable or disable this script just change the execution</span><br><span class="hljs-comment"># bits.</span><br><span class="hljs-comment">#</span><br><span class="hljs-comment"># By default this script does nothing.</span><br><br><span class="hljs-comment">#/etc/init.d/nginx start</span><br><br></code></pre></td></tr></table></figure>

<h1 id="更强大的-sed-功能"><a href="#更强大的-sed-功能" class="headerlink" title="更强大的 sed 功能"></a>更强大的 sed 功能</h1><h2 id="替换"><a href="#替换" class="headerlink" title="替换"></a>替换</h2><p>与上面打印、删除文本行不同的是，<code>sed</code> 的替换命令可以将文本流中的摸个字符串全部替换成另一个字符串。</p>
<p><strong>使用 sed 替换文本</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><code class="hljs bash">$ cat demo.c <br><span class="hljs-comment"># include &lt;stdio.h&gt;</span><br><span class="hljs-comment"># include &lt;math.h&gt;</span><br><br>long int power(int, int);<br><br>int <span class="hljs-function"><span class="hljs-title">main</span></span>() &#123;<br>    int base, n;<br>    scanf(<span class="hljs-string">&quot;%d, %d\n&quot;</span>, &amp;base, &amp;n);<br>    <span class="hljs-built_in">printf</span>(<span class="hljs-string">&quot;The power is: %d\n&quot;</span>, power(base, n));<br>&#125;<br><br>long int power(int base, int n) <br>&#123;<br>    <span class="hljs-built_in">return</span> base^n;<br>&#125;<br>$ sed -e <span class="hljs-string">&#x27;s/power/aurora/g&#x27;</span> /tmp/demo.c<br><span class="hljs-comment"># include &lt;stdio.h&gt;</span><br><span class="hljs-comment"># include &lt;math.h&gt;</span><br><br>long int aurora(int, int); <span class="hljs-comment"># power</span><br><br>int <span class="hljs-function"><span class="hljs-title">main</span></span>() &#123;<br>    int base, n;<br>    scanf(<span class="hljs-string">&quot;%d, %d\n&quot;</span>, &amp;base, &amp;n);<br>    <span class="hljs-built_in">printf</span>(<span class="hljs-string">&quot;The aurora is: %d\n&quot;</span>, aurora(base, n)); <span class="hljs-comment"># power</span><br>&#125;<br><br>long int aurora(int base, int n)  <span class="hljs-comment"># power</span><br>&#123;<br>    <span class="hljs-built_in">return</span> base^n;<br>&#125;<br>$<br></code></pre></td></tr></table></figure>

<p>在上述例子中使用了命令 <code>&#39;s/power/aurora/g&#39;</code>。命令全局查找文件 <code>demo.c</code> 中的 ’power‘ 关键爱你字符串，替换为 ’aurora‘。其中 <code>s</code> 是替换命令，<code>g</code> 告诉 <code>sed</code></p>
<p>执行全局查找替换。</p>
<p><strong>地址范围+替换操作</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><code class="hljs bash">$ sed -e <span class="hljs-string">&#x27;1,10s/power/aurora/g&#x27;</span> /tmp/demo.c <span class="hljs-comment"># 替换1到10行中的所有power</span><br><span class="hljs-comment"># include &lt;stdio.h&gt;</span><br><span class="hljs-comment"># include &lt;math.h&gt;</span><br><br>long int aurora(int, int);	<span class="hljs-comment"># 此处被替换</span><br><br>int <span class="hljs-function"><span class="hljs-title">main</span></span>() &#123;<br>    int base, n;<br>    scanf(<span class="hljs-string">&quot;%d, %d\n&quot;</span>, &amp;base, &amp;n);<br>    <span class="hljs-built_in">printf</span>(<span class="hljs-string">&quot;The aurora is: %d\n&quot;</span>, aurora(base, n)); <span class="hljs-comment"># 此处被替换</span><br>&#125;<br><br>long int power(int base, int n) <span class="hljs-comment"># 此处没被替换</span><br>&#123;<br>    <span class="hljs-built_in">return</span> base^n;<br>&#125;<br>$ sed -e <span class="hljs-string">&#x27;/main[[:space:]]*(/,/^)/s/power/aurora/g&#x27;</span> /tmp/demo.c <span class="hljs-comment"># 替换 main 函数中所有 power（没起作用，后面的 power都被替换了）</span><br><span class="hljs-comment"># include &lt;stdio.h&gt;</span><br><span class="hljs-comment"># include &lt;math.h&gt;</span><br><br>long int power(int, int);<br><br>int <span class="hljs-function"><span class="hljs-title">main</span></span>() &#123;<br>    int base, n;<br>    scanf(<span class="hljs-string">&quot;%d, %d\n&quot;</span>, &amp;base, &amp;n);<br>    <span class="hljs-built_in">printf</span>(<span class="hljs-string">&quot;The aurora is: %d\n&quot;</span>, aurora(base, n)); <span class="hljs-comment"># 此处被替换</span><br>&#125;<br><br>long int aurora(int base, int n) <span class="hljs-comment"># 此处被替换</span><br>&#123;<br>    <span class="hljs-built_in">return</span> base^n;<br>&#125;<br></code></pre></td></tr></table></figure>

<h2 id="组合命令的使用"><a href="#组合命令的使用" class="headerlink" title="组合命令的使用"></a>组合命令的使用</h2><p>有些时候可能需要将多条命令应用到同一行中，这就需要将命令组合使用。</p>
<p>最简单的组合命令方法是使用分号分隔命令，例如：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><code class="hljs bash">$ cat /tmp/passwd.bak<br>root:x:0:0:root:/root:/bin/bash<br>daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin<br>bin:x:2:2:bin:/bin:/usr/sbin/nologin<br>sys:x:3:3:sys:/dev:/usr/sbin/nologin<br>sync:x:4:65534:sync:/bin:/bin/sync<br>games:x:5:60:games:/usr/games:/usr/sbin/nologin<br>man:x:6:12:man:/var/cache/man:/usr/sbin/nologin<br>lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin<br>mail:x:8:8:mail:/var/mail:/usr/sbin/nologin<br>news:x:9:9:news:/var/spool/news:/usr/sbin/nologin<br>$ sed -n -e <span class="hljs-string">&#x27;=;p&#x27;</span> /tmp/passwd.bak<br>1<br>root:x:0:0:root:/root:/bin/bash<br>2<br>daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin<br>3<br>bin:x:2:2:bin:/bin:/usr/sbin/nologin<br>4<br>sys:x:3:3:sys:/dev:/usr/sbin/nologin<br>5<br>sync:x:4:65534:sync:/bin:/bin/sync<br>6<br>games:x:5:60:games:/usr/games:/usr/sbin/nologin<br>7<br>man:x:6:12:man:/var/cache/man:/usr/sbin/nologin<br>8<br>lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin<br>9<br>mail:x:8:8:mail:/var/mail:/usr/sbin/nologin<br>10<br>news:x:9:9:news:/var/spool/news:/usr/sbin/nologin<br></code></pre></td></tr></table></figure>

<p>这个命令分为两部分，一部分是等号（=），一部分是 ‘p’ 命令。命令之间使用分号（;）隔开。等号命令告诉 <code>sed</code> 打印行号，‘p’  命令告诉 <code>sed</code> 打印该行。</p>
<p>如果你不想通过分号来组合多个命令，也可以通过一个 <code>-e</code> 来连接一个命令，那么上面的命令等同于 <code>sed -n -e &#39;=&#39; -e &#39;p&#39; /tmp/passwd.bak</code>。</p>
<p>如果我们要执行多条命令，甚至 <code>-e</code> 命令也不够使用时，可以将命令写入一个文本文件中，然后通过 <code>-f</code> 参数引用命令，如下所示：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><code class="hljs bash">$ cat handle.sed<br>1d<br>s:sbin/nologin:bin/zsg:g<br>p<br>$ cat passwd.bak <br>root:x:0:0:root:/root:/bin/bash<br>daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin<br>bin:x:2:2:bin:/bin:/usr/sbin/nologin<br>sys:x:3:3:sys:/dev:/usr/sbin/nologin<br>sync:x:4:65534:sync:/bin:/bin/sync<br>games:x:5:60:games:/usr/games:/usr/sbin/nologin<br>man:x:6:12:man:/var/cache/man:/usr/sbin/nologin<br>lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin<br>mail:x:8:8:mail:/var/mail:/usr/sbin/nologin<br>news:x:9:9:news:/var/spool/news:/usr/sbin/nologin<br>$ sed -n -f handle.sed /tmp/passwd.bak<br>daemon:x:1:1:daemon:/usr/sbin:/usr/bin/zsg<br>bin:x:2:2:bin:/bin:/usr/bin/zsg<br>sys:x:3:3:sys:/dev:/usr/bin/zsg<br>sync:x:4:65534:sync:/bin:/bin/sync<br>games:x:5:60:games:/usr/games:/usr/bin/zsg<br>man:x:6:12:man:/var/cache/man:/usr/bin/zsg<br>lp:x:7:7:lp:/var/spool/lpd:/usr/bin/zsg<br>mail:x:8:8:mail:/var/mail:/usr/bin/zsg<br>news:x:9:9:news:/var/spool/news:/usr/bin/zsg<br></code></pre></td></tr></table></figure>

<p>这个例子中，sed 要执行的命令写入<code>handle.sed</code> 文件中，文件中 3 行分别表示：</p>
<p>1）<code>1d</code> 告诉 <strong>sed</strong> 删除 passwd.bak 文件的第一行</p>
<p>2）<code>s:sbin/nologin:bin/zsg:g</code> 替换命令，将 ‘sbin/nologin’ 替换为 <code>bin/zsg</code>。由于替换内容中有 ‘/’ 符号，因此在 “s///” 命令中，这里使用 ‘:’代替‘/’符号，这样就不需要转义‘/’ 字符了。</p>
<p>3）<code>p</code> 命令明确告诉 <strong>sed</strong> 在 <code>-n</code> 模式下打印该行。</p>
<h2 id="将多个命令应用到一个地址范围"><a href="#将多个命令应用到一个地址范围" class="headerlink" title="将多个命令应用到一个地址范围"></a>将多个命令应用到一个地址范围</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><code class="hljs bash">$ cat passwd.bak <br>root:x:0:0:root:/root:/bin/bash<br>daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin<br>bin:x:2:2:bin:/bin:/usr/sbin/nologin<br>sys:x:3:3:sys:/dev:/usr/sbin/nologin<br>sync:x:4:65534:sync:/bin:/bin/sync<br>games:x:5:60:games:/usr/games:/usr/sbin/nologin<br>man:x:6:12:man:/var/cache/man:/usr/sbin/nologin<br>lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin<br>mail:x:8:8:mail:/var/mail:/usr/sbin/nologin<br>news:x:9:9:news:/var/spool/news:/usr/sbin/nologin<br>$ sed -n -e <span class="hljs-string">&#x27;1,5&#123;s:sbin/nologin:bin/zsh:g;s/:/|/g;p&#125;&#x27;</span> /tmp/passwd.bak<br>root|x|0|0|root|/root|/bin/bash<br>daemon|x|1|1|daemon|/usr/sbin|/usr/bin/zsh<br>bin|x|2|2|bin|/bin|/usr/bin/zsh<br>sys|x|3|3|sys|/dev|/usr/bin/zsh<br>sync|x|4|65534|sync|/bin|/bin/sync<br></code></pre></td></tr></table></figure>

<p>命令 <code>&#123;s:sbin/nologin:bin/zsh:g;s/:/|/g;p&#125;</code> 同时执行了下面的操作：</p>
<p>1）将 ‘sbin/nologin’ 替换为 ‘bin/zsh’;</p>
<p>2）将 ‘:’ 替换为 ‘|’；</p>
<p>3）打印输出行</p>
<h2 id="sed-i"><a href="#sed-i" class="headerlink" title="sed -i"></a>sed -i</h2><p><strong>sed</strong> 的 <code>-i</code> 参数作用是将命令执行的结果直接作用与操作的文件，而不是缓冲区。</p>
<p><strong>示例</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><code class="hljs bash">$ cat /tmp/passwd.bak<br>root:x:0:0:root:/root:/bin/bash<br>daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin<br>bin:x:2:2:bin:/bin:/usr/sbin/nologin<br>sys:x:3:3:sys:/dev:/usr/sbin/nologin<br>sync:x:4:65534:sync:/bin:/bin/sync<br>games:x:5:60:games:/usr/games:/usr/sbin/nologin<br>man:x:6:12:man:/var/cache/man:/usr/sbin/nologin<br>lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin<br>mail:x:8:8:mail:/var/mail:/usr/sbin/nologin<br>news:x:9:9:news:/var/spool/news:/usr/sbin/nologin<br>$ sed -i <span class="hljs-string">&#x27;s/:/|/g&#x27;</span> /tmp/passwd.bak | grep cat <span class="hljs-comment"># 将文件中所有的 ：替换为 |</span><br>$ cat /tmp/passwd.bak<br>root|x|0|0|root|/root|/bin/bash<br>daemon|x|1|1|daemon|/usr/sbin|/usr/sbin/nologin<br>bin|x|2|2|bin|/bin|/usr/sbin/nologin<br>sys|x|3|3|sys|/dev|/usr/sbin/nologin<br>sync|x|4|65534|sync|/bin|/bin/sync<br>games|x|5|60|games|/usr/games|/usr/sbin/nologin<br>man|x|6|12|man|/var/cache/man|/usr/sbin/nologin<br>lp|x|7|7|lp|/var/spool/lpd|/usr/sbin/nologin<br>mail|x|8|8|mail|/var/mail|/usr/sbin/nologin<br>news|x|9|9|news|/var/spool/news|/usr/sbin/nologin<br>$ sed -i <span class="hljs-string">&#x27;s:sbin/nologin:bin/szh:g&#x27;</span> /tmp/passwd.bak<br>$ cat /tmp/passwd.bak<br>root|x|0|0|root|/root|/bin/bash<br>daemon|x|1|1|daemon|/usr/sbin|/usr/bin/szh<br>bin|x|2|2|bin|/bin|/usr/bin/szh<br>sys|x|3|3|sys|/dev|/usr/bin/szh<br>sync|x|4|65534|sync|/bin|/bin/sync<br>games|x|5|60|games|/usr/games|/usr/bin/szh<br>man|x|6|12|man|/var/cache/man|/usr/bin/szh<br>lp|x|7|7|lp|/var/spool/lpd|/usr/bin/szh<br>mail|x|8|8|mail|/var/mail|/usr/bin/szh<br>news|x|9|9|news|/var/spool/news|/usr/bin/szh<br></code></pre></td></tr></table></figure>

<p>由上面的例子看到 <strong>sed</strong> 的 <code>-i</code> 参数实用性要大得多，往往我们在通过脚本修改某些配置文件时，通过 <code>sed -i</code> 命令直接操作配置文件中要修改的哪一行就可以实现，而不需要打开这个配置文件。</p>

            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/categories/Shell/">Shell</a>
                    
                  </div>
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/Linux/">Linux</a>
                    
                      <a class="hover-with-bg" href="/tags/Shell/">Shell</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">
                  
                    本博客所有文章除特别声明外，均采用 <a target="_blank" href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！
                  
                </p>
              
              
                <div class="post-prevnext">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2019/05/29/shell/shell-%E6%96%87%E6%9C%AC%E5%A4%84%E7%90%86%E5%88%A9%E5%99%A8%20awk/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">【转】shell-文本处理利器 awk</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2019/05/21/shell/shell-%E6%96%87%E4%BB%B6%E5%92%8C%E6%96%87%E4%BB%B6%E7%B3%BB%E7%BB%9F/">
                        <span class="hidden-mobile">shell-文件和文件系统</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
    

    
  </main>

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
     <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
  </div>
  

  

  
</footer>


  <!-- SCRIPTS -->
  
  <script  src="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js" ></script>
<script  src="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>

<!-- Plugins -->


  <script  src="/js/local-search.js" ></script>



  
    <script  src="/js/img-lazyload.js" ></script>
  



  



  
    <script  src="https://cdn.jsdelivr.net/npm/tocbot@4/dist/tocbot.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/anchor-js@4/anchor.min.js" ></script>
  
  
    <script defer src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js" ></script>
  






  <script  src="https://cdn.jsdelivr.net/npm/typed.js@2/lib/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var title = document.getElementById('subtitle').title;
      
        typing(title);
      
    })(window, document);
  </script>















<!-- 主题的启动项 保持在最底部 -->
<script  src="/js/boot.js" ></script>


</body>
</html>
